package io.dbw.modules.business.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.dbw.common.utils.DateUtils;
import io.dbw.common.utils.PageUtils;
import io.dbw.modules.business.dao.SysBooksDao;
import io.dbw.modules.business.entity.SysBooksEntity;
import io.dbw.modules.business.service.SysBooksService;
import io.dbw.modules.business.vo.HomeVO;
import org.apache.commons.collections4.MapUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



@Service("sysBooksService")
public class SysBooksServiceImpl extends ServiceImpl<SysBooksDao, SysBooksEntity> implements SysBooksService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Integer pageNo= MapUtils.getInteger(params,"pageNo",1);
        Integer pageSize= MapUtils.getInteger(params,"pageSize",10);
        Page page = new Page<>(pageNo, pageSize);
        List<SysBooksEntity> list =  baseMapper.queryBooksPage(page,params);
        page.setRecords(list);
        return new PageUtils(page);
    }

    @Override
    public HomeVO queryBooksStatistics() {
        Map<String ,Object> param=new HashMap<>();
        String day = DateUtils.format(new Date());
        param.put("startDay",day+" 00:00:00");
        param.put("endDay",day+" 23:59:59");
        Date[] weekStartAndEnd = DateUtils.getWeekStartAndEnd(0);
        param.put("startWeek",DateUtils.format(weekStartAndEnd[0])+" 00:00:00");
        param.put("endWeek",DateUtils.format(weekStartAndEnd[1])+" 23:59:59");
        param.put("startMonth",DateUtils.getFirstDayOfMonth()+" 00:00:00");
        param.put("endMonth",day+" 23:59:59");
        return baseMapper.queryBooksStatistics(param);
    }
}